VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "ClsPrecio"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Public WithEvents orset As ClsRecordset
Attribute orset.VB_VarHelpID = -1
'Private sql As ClsSQL

Public Event DataChanged()

Public codigo As String
Public codServicio As String
Public codMoneda As String
Public tipo As String
Public monto As Double
Public descripcion As String

Public moneda As ClsMoneda

Private Sub Class_Initialize()
    Set orset = New ClsRecordset
    Set moneda = New ClsMoneda
    orset.setCampos concatenaVectores(dbCampos(pre), dbCampos(mon))
    orset.setTablas Array(pre, mon)
End Sub
Private Sub Class_Terminate()
    Set orset = Nothing
End Sub

Public Sub consulta(Optional servicioCod As String = "")
    If servicioCod <> "" Then
        orset.consulta Array(pre_mon_id & "=" & mon_id, pre_ser_id & "=" & servicioCod)
    Else
        orset.consulta Array(pre_mon_id & "=" & mon_id)
    End If
End Sub

Public Sub consultaTipoServicio(tipoServicioCod As String)
    orset.consulta Array(pre_mon_id & "=" & mon_id)
End Sub

Public Sub consultaSubtipCliente(clienteCod As String, Optional servicioCod As String = "", Optional tipopreciocod As String = "", Optional muestraSoloEspeciales As Boolean = False)
    If Not muestraSoloEspeciales And Not preciosesp(servicioCod, clienteCod) Then
        'si no hay precios especiales y se ha seleccionado mostrar
        'todos los precios en caso de que no haya precios especiales
        consulta servicioCod
        Exit Sub
    End If
    Dim condiciones As Variant
    condiciones = Array(pre_mon_id & "=" & mon_id, _
                        ptc_pre_id & "=" & pre_id, _
                        ptc_tcl_id & "=" & tcl_id, _
                        tcl_id & "=" & ctc_tcl_id, _
                        ctc_cli_id & "='" & clienteCod & "'")
    If (servicioCod <> "") Then
        condiciones = concatenaVectores(condiciones, Array(pre_ser_id & "=" & servicioCod))
    End If
    orset.consultaGral , Array(pre, mon, ptc, tcl, ctc), _
                       condiciones
End Sub

Public Sub consultaDatos(codig As String)
    orset.consulta Array(pre_mon_id & "=" & mon_id, _
                         pre_id & "=" & codig)
    orset.CierraRec
End Sub

Public Function preciosesp(codser As String, codcli As String) As Boolean
    orset.consultaGral , Array(pre, mon, ptc, tcl, ctc), _
                       Array(pre_mon_id & "=" & mon_id, _
                             ptc_pre_id & "=" & pre_id, _
                             pre_ser_id & "=" & codser, _
                             ptc_tcl_id & "=" & tcl_id, _
                             ctc_tcl_id & "=" & tcl_id, _
                             ctc_cli_id & "='" & codcli & "'"), , False
    If (orset.numRegistros > 0) Then
        preciosesp = True
    Else
        preciosesp = False
    End If
    orset.CierraRec
End Function
Public Sub AgregaTipoCliente(codTipcli As String)
    orset.sInsertGral Array(ptc_tcl_id, ptc_pre_id), _
                      Array(codTipcli, Me.codigo), _
                      Array(ptc), False, False
End Sub
Public Sub QuitaSubtiposCliente()
    orset.sDeleteGral Array(ptc), _
                      Array(ptc_pre_id & "=" & Me.codigo)
End Sub
Public Sub Nuevo(descr As String, monpre As String, serCod As String, tipocod As String, monedacod As String)
    orset.sInsert Array("", serCod, monedacod, tipocod, monpre, descr)
End Sub
Public Sub Modificar(codig As String, descr As String, monpre As String, serCod As String, tipocod As String, monedacod As String)
    orset.sUpdate Array(codig, serCod, monedacod, tipocod, monpre, descr)
End Sub
Public Sub Borrar(codig As String)
    Me.codigo = codig
    QuitaSubtiposCliente
    orset.sDelete Array(pre_id & "=" & codig)
End Sub
Private Sub Reload_members()
    With orset
        codigo = .getDato(pre_id)
        tipo = .getDato(pre_tipo)
        codServicio = .getDato(pre_ser_id)
        codMoneda = .getDato(pre_mon_id)
        descripcion = .getDato(pre_descripcion)
        monto = .getDato(pre_monto)
        If .registrando Then
            moneda.consultaDatos codMoneda
            .registrando = False
        Else
            moneda.Reload_members orset
        End If
    End With
    RaiseEvent DataChanged
End Sub
Public Sub llenaCombo(cajaCombo As ComboBox, conCodigo As Boolean, servicioCod As String, Optional clicod As String = "")
    Dim i As Integer
    If clicod <> "" Then
        Me.consultaSubtipCliente clicod, servicioCod
    Else
        Me.consulta servicioCod
    End If
    i = 0
    cajaCombo.Clear
    If conCodigo Then
        While orset.CanMoveNext
            cajaCombo.AddItem codigo & " - " & descripcion
            cajaCombo.ItemData(i) = codigo
            orset.MoveNext
            i = i + 1
        Wend
    Else
        While orset.CanMoveNext
            cajaCombo.AddItem descripcion
            cajaCombo.ItemData(i) = codigo
            orset.MoveNext
            i = i + 1
        Wend
    End If
    If cajaCombo.ListCount = 1 Then
        'si solo hay un precio lo selecciona
        cajaCombo.ListIndex = 0
    End If
End Sub

Private Sub orset_DataChanged()
    Reload_members
End Sub
